package com.easy.web.controller;

import org.springframework.stereotype.Service;
import org.thymeleaf.util.StringUtils;

@Service
public class TestService {


    private static Object LOCK = new Object();

    public void service() {
        System.out.println("这是 service ....");
    }

    public static void main(String[] args) {

        while (true) {
            try {
                d();
            } catch (Exception e) {
                e.printStackTrace();
                continue;
            }
        }
    }


    public static void d() {
        int i = 0;
        int b = 10;
        System.out.println(b / i);
        // 1. 查询redis
        String result = getDataRedis();
        if (StringUtils.isEmpty(result)) {
            // load db
            synchronized (LOCK) {
                result = getDataByDb();
                //set value
                setDataToKv("key", result);
            }
        }
    }

    public static void setDataToKv(String key, String value) {
    }

    public static String getDataRedis() {
        return "";
    }

    public static String getDataByDb() {
        return "";
    }
}
